<template>
  <div class="homepage-container">
    <h1>{{ getCurrentTimePeriod() }}好，{{ username }}!</h1>
    <div class="homepage-card-container">
      <el-card class="homepage-card-approve" shadow="hover">
        <h1>{{ approve }}</h1>
        <span>待审核</span>
        <img class="homepage-card-img" src="../../assets/imgs/待审核.png">
      </el-card>
      <el-card class="homepage-card-day" shadow="hover">
        <h1>{{ day }}</h1>
        <span>日期</span>
        <img class="homepage-card-img" src="../../assets/imgs/星期.png">
      </el-card>
      <el-card class="homepage-card-course" shadow="hover">
        <h1>{{ course }}</h1>
        <span>课程</span>
        <img class="homepage-card-img" src="../../assets/imgs/课程.png">
      </el-card>
      <el-card class="homepage-card-exam" shadow="hover">
        <h1>{{ exam }}</h1>
        <span>考试</span>
        <img class="homepage-card-img" src="../../assets/imgs/考试.png">
      </el-card>
    </div>
  </div>
</template>

<script setup>
import api from '@/api/api';
import { onMounted, ref } from 'vue';

const username = sessionStorage.getItem('username')
const day = ref('星期一')
const approve = ref(0)
const course = ref(0)
const exam = ref(0)

const getCurrentTimePeriod = () => {
  let now = new Date()
  let hour = now.getHours()
  let time_period = ''
  if (0 <= hour && hour < 5) {
    time_period = '凌晨'
  } else if (5 <= hour && hour < 9) {
    time_period = '早上'
  } else if (9 <= hour && hour < 12) {
    time_period = '上午'
  } else if (12 <= hour && hour < 14) {
    time_period = '中午'
  } else if (14 <= hour && hour < 17) {
    time_period = '下午'
  } else if (17 <= hour && hour < 19) {
    time_period = '傍晚'
  } else if (19 <= hour && hour <= 24) {
    time_period = '晚上'
  }
  return time_period
}

onMounted(() => {
  // 赋值day
  let now = new Date()
  let weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
  day.value = weeks[now.getDay()]
  // 赋值exam
  api.final_exam.page_by_invigilator_id(
    sessionStorage.getItem('userid'), 1, 10
  ).then((res) => {
    exam.value = res.data.data.total
  }).catch((err) => {
    console.log(err)
  })
  // 赋值course
  api.scheduled_course.page_by_teacher_id(
    sessionStorage.getItem('userid'), 1, 10
  ).then((res) => {
    course.value = res.data.data.total
  }).catch((err) => {
    console.log(err)
  })
  // 赋值approve
  approve.value = 0
  api.classroom_application.page_by_id(
    sessionStorage.getItem('userid'), 1, 10, '', 2, '', ''
  ).then((res) => {
    approve.value += res.data.data.total
  }).catch((err) => {
    console.log(err)
  })
  api.exampaper_application.page_by_id(
    1, 10, sessionStorage.getItem('userid'), '', '', 2
  ).then((res) => {
    approve.value += res.data.data.total
  }).catch((err) => {
    console.log(err)
  })
  api.exam_method_application.page_by_id(
    1, 10, sessionStorage.getItem('userid'), '', '', 2
  ).then((res) => {
    approve.value += res.data.data.total
  }).catch((err) => {
    console.log(err)
  })
})
</script>

<style></style>